In [114]:
import sys
!{sys.executable} --version
Python 3.7.4

import necessary libraries

In [50]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

for interactive visuals,prefer plotly

In [53]:
import plotly.express as px
In [54]:
dir(px)
Out[54]:
['Constant',
 'IdentityMap',
 'NO_COLOR',
 'Range',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '_chart_types',
 '_core',
 '_doc',
 '_imshow',
 '_special_inputs',
 'absolute_import',
 'area',
 'bar',
 'bar_polar',
 'box',
 'choropleth',
 'choropleth_mapbox',
 'colors',
 'data',
 'defaults',
 'density_contour',
 'density_heatmap',
 'density_mapbox',
 'funnel',
 'funnel_area',
 'get_trendline_results',
 'histogram',
 'imshow',
 'line',
 'line_3d',
 'line_geo',
 'line_mapbox',
 'line_polar',
 'line_ternary',
 'optional_imports',
 'parallel_categories',
 'parallel_coordinates',
 'pd',
 'pie',
 'scatter',
 'scatter_3d',
 'scatter_geo',
 'scatter_mapbox',
 'scatter_matrix',
 'scatter_polar',
 'scatter_ternary',
 'set_mapbox_access_token',
 'strip',
 'sunburst',
 'timeline',
 'treemap',
 'violin']
In [ ]:
!pip install plotly
In [55]:
import plotly
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, plot, iplot
In [117]:
dir(plotly)
Out[117]:
['__version__',
 'colors',
 'data',
 'graph_objects',
 'graph_objs',
 'io',
 'offline',
 'tools',
 'utils']
In [116]:
print(plotly.__version__)
4.9.0
In [59]:
current_data = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv')
current_data.head()
Out[59]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
In [ ]:
'''current_data.to_csv('F:/Spatial Analysis/current_covid_29Sep_data')'''
In [65]:
type(current_data)
Out[65]:
pandas.core.frame.DataFrame
In [ ]:
 

plotting of confirmed cases

animation_frame--> Values from this column or array_like are used to assign marks to animation frames.

to map country to map-assign locations='Country' & locationmode='country names' ,

 to assign confirmed cases of each country on map and I want colorbar as well u have to asisgn color='Confirmed'
In [67]:
# Choropleth Map of the World
fig = px.choropleth(current_data,locations='Country',locationmode='country names',color='Confirmed',animation_frame='Date')
fig.update_layout(title='Choropleth Map of Confirmed Cases -till today',template="plotly_dark")
fig.show()
Above, We created the World Map but if we want to make a specific map for a continent we will use the scope.Let's see it by two examples of Asia and Europe.
In [68]:
# Continent Map using Choropleth
fig = px.choropleth(current_data,locations='Country',locationmode='country names',color='Confirmed',animation_frame='Date',scope='europe')
fig.update_layout(title='Choropleth Map of Confirmed Cases - Europe till today',template="plotly_dark")
fig.show()
In [69]:
fig = px.choropleth(current_data,locations='Country',locationmode='country names',color='Confirmed',animation_frame='Date',scope='asia')
fig.update_layout(title='Choropleth Map of Confirmed Cases - Asia on 28-09-2020',template="plotly_dark")
fig.show()
Spread over Time
In [70]:
fig = px.scatter_geo(current_data,locations='Country',locationmode='country names',color='Confirmed',size='Confirmed',hover_name="Country",animation_frame='Date',title='Spread over Time')
fig.update(layout_coloraxis_showscale=False,layout_template="plotly_dark")
fig.show()

The spread is very fast. It started in China and spread to the complete world

plotting of Recovered cases

In [71]:
fig = px.choropleth(current_data,locations='Country',locationmode='country names',color='Recovered',animation_frame='Date')
fig.update_layout(title='Choropleth Map of Recovered Cases -till today',template="plotly_dark")
fig.show()

Similar to Choropleth maps, we have another cool interactive map called ‘Scatter Plot

In [72]:
fig = px.scatter_geo(current_data,locations='Country',locationmode='country names',color='Recovered',size='Recovered',hover_name="Country",animation_frame='Date',title='Recovery over Time')
fig.update(layout_coloraxis_showscale=False,layout_template="plotly_dark")
fig.show()

From above interactive map we can say that recovery is very slow as compared to the spread.

The only thing we can do is prevention. We have to follow some precautions:

1.WE have to wash our hands
2.WE have to cover our face with fask
3.We dont have to touch our face
4.Mainntain Social Distancing
5.HOME Stay if you can
plotting of Deaths
In [73]:
fig = px.choropleth(current_data,locations='Country',locationmode='country names',color='Deaths',animation_frame='Date')
fig.update_layout(title='Choropleth Map of Deaths -till today',template="plotly_dark")
fig.show()
In [111]:
worldometer = pd.read_csv('F:/Spatial Analysis/archive (1)/worldometer_data.csv')
worldometer.head()
Out[111]:
Country/Region Continent Population TotalCases NewCases TotalDeaths NewDeaths TotalRecovered NewRecovered ActiveCases Serious,Critical Tot Cases/1M pop Deaths/1M pop TotalTests Tests/1M pop WHO Region
0 USA North America 3.311981e+08 5032179 NaN 162804.0 NaN 2576668.0 NaN 2292707.0 18296.0 15194.0 492.0 63139605.0 190640.0 Americas
1 Brazil South America 2.127107e+08 2917562 NaN 98644.0 NaN 2047660.0 NaN 771258.0 8318.0 13716.0 464.0 13206188.0 62085.0 Americas
2 India Asia 1.381345e+09 2025409 NaN 41638.0 NaN 1377384.0 NaN 606387.0 8944.0 1466.0 30.0 22149351.0 16035.0 South-EastAsia
3 Russia Europe 1.459409e+08 871894 NaN 14606.0 NaN 676357.0 NaN 180931.0 2300.0 5974.0 100.0 29716907.0 203623.0 Europe
4 South Africa Africa 5.938157e+07 538184 NaN 9604.0 NaN 387316.0 NaN 141264.0 539.0 9063.0 162.0 3149807.0 53044.0 Africa

highlighting maximum values

In [112]:
worldometer_new.style.background_gradient(cmap='RdPu')
Out[112]:
Country/Region Continent Population TotalCases TotalDeaths TotalRecovered ActiveCases Serious,Critical Tot Cases/1M pop Deaths/1M pop TotalTests Tests/1M pop WHO Region
0 USA North America 331198130.000000 5032179 162804.000000 2576668.000000 2292707.000000 18296.000000 15194.000000 492.000000 63139605.000000 190640.000000 Americas
1 Brazil South America 212710692.000000 2917562 98644.000000 2047660.000000 771258.000000 8318.000000 13716.000000 464.000000 13206188.000000 62085.000000 Americas
2 India Asia 1381344997.000000 2025409 41638.000000 1377384.000000 606387.000000 8944.000000 1466.000000 30.000000 22149351.000000 16035.000000 South-EastAsia
3 Russia Europe 145940924.000000 871894 14606.000000 676357.000000 180931.000000 2300.000000 5974.000000 100.000000 29716907.000000 203623.000000 Europe
4 South Africa Africa 59381566.000000 538184 9604.000000 387316.000000 141264.000000 539.000000 9063.000000 162.000000 3149807.000000 53044.000000 Africa
5 Mexico North America 129066160.000000 462690 50517.000000 308848.000000 103325.000000 3987.000000 3585.000000 391.000000 1056915.000000 8189.000000 Americas
6 Peru South America 33016319.000000 455409 20424.000000 310337.000000 124648.000000 1426.000000 13793.000000 619.000000 2493429.000000 75521.000000 Americas
7 Chile South America 19132514.000000 366671 9889.000000 340168.000000 16614.000000 1358.000000 19165.000000 517.000000 1760615.000000 92022.000000 Americas
8 Colombia South America 50936262.000000 357710 11939.000000 192355.000000 153416.000000 1493.000000 7023.000000 234.000000 1801835.000000 35374.000000 Americas
9 Spain Europe 46756648.000000 354530 28500.000000 nan nan 617.000000 7582.000000 610.000000 7064329.000000 151087.000000 Europe
10 Iran Asia 84097623.000000 320117 17976.000000 277463.000000 24678.000000 4156.000000 3806.000000 214.000000 2612763.000000 31068.000000 EasternMediterranean
11 UK Europe 67922029.000000 308134 46413.000000 nan nan 73.000000 4537.000000 683.000000 17515234.000000 257873.000000 Europe
12 Saudi Arabia Asia 34865919.000000 284226 3055.000000 247089.000000 34082.000000 1915.000000 8152.000000 88.000000 3635705.000000 104277.000000 EasternMediterranean
13 Pakistan Asia 221295851.000000 281863 6035.000000 256058.000000 19770.000000 809.000000 1274.000000 27.000000 2058872.000000 9304.000000 EasternMediterranean
14 Bangladesh Asia 164851401.000000 249651 3306.000000 143824.000000 102521.000000 nan 1514.000000 20.000000 1225124.000000 7432.000000 South-EastAsia
15 Italy Europe 60452568.000000 249204 35187.000000 201323.000000 12694.000000 42.000000 4122.000000 582.000000 7099713.000000 117443.000000 Europe
16 Turkey Asia 84428331.000000 237265 5798.000000 220546.000000 10921.000000 580.000000 2810.000000 69.000000 5081802.000000 60191.000000 Europe
17 Argentina South America 45236884.000000 228195 4251.000000 99852.000000 124092.000000 1150.000000 5044.000000 94.000000 794544.000000 17564.000000 Americas
18 Germany Europe 83811260.000000 215210 9252.000000 196200.000000 9758.000000 236.000000 2568.000000 110.000000 8586648.000000 102452.000000 Europe
19 France Europe 65288306.000000 195633 30312.000000 82460.000000 82861.000000 384.000000 2996.000000 464.000000 3992206.000000 61147.000000 Europe
20 Iraq Asia 40306025.000000 140603 5161.000000 101025.000000 34417.000000 517.000000 3488.000000 128.000000 1092741.000000 27111.000000 EasternMediterranean
21 Philippines Asia 109722719.000000 119460 2150.000000 66837.000000 50473.000000 239.000000 1089.000000 20.000000 1669996.000000 15220.000000 WesternPacific
22 Indonesia Asia 273808365.000000 118753 5521.000000 75645.000000 37587.000000 nan 434.000000 20.000000 1633156.000000 5965.000000 South-EastAsia
23 Canada North America 37775022.000000 118561 8966.000000 103106.000000 6489.000000 2263.000000 3139.000000 237.000000 4319172.000000 114339.000000 Americas
24 Qatar Asia 2807805.000000 112092 178.000000 108831.000000 3083.000000 77.000000 39922.000000 63.000000 511000.000000 181993.000000 EasternMediterranean
25 Kazakhstan Asia 18798667.000000 95942 1058.000000 68871.000000 26013.000000 221.000000 5104.000000 56.000000 2163713.000000 115099.000000 Europe
26 Egypt Africa 102516525.000000 95006 4951.000000 48898.000000 41157.000000 41.000000 927.000000 48.000000 135000.000000 1317.000000 EasternMediterranean
27 Ecuador South America 17668824.000000 90537 5877.000000 71318.000000 13342.000000 378.000000 5124.000000 333.000000 258582.000000 14635.000000 Americas
28 Bolivia South America 11688459.000000 86423 3465.000000 27373.000000 55585.000000 71.000000 7394.000000 296.000000 183583.000000 15706.000000 Americas
29 Sweden Europe 10105596.000000 81967 5766.000000 nan nan 38.000000 8111.000000 571.000000 863315.000000 85429.000000 Europe
30 Oman Asia 5118446.000000 80713 492.000000 70910.000000 9311.000000 177.000000 15769.000000 96.000000 309212.000000 60411.000000 EasternMediterranean
31 Israel Asia 9197590.000000 79559 576.000000 53427.000000 25556.000000 358.000000 8650.000000 63.000000 1872453.000000 203581.000000 Europe
32 Ukraine Europe 43705858.000000 76808 1819.000000 42524.000000 32465.000000 158.000000 1757.000000 42.000000 1116641.000000 25549.000000 Europe
33 Dominican Republic North America 10858648.000000 76536 1246.000000 40539.000000 34751.000000 317.000000 7048.000000 115.000000 281926.000000 25963.000000 Americas
34 Panama North America 4321282.000000 71418 1574.000000 45658.000000 24186.000000 161.000000 16527.000000 364.000000 240995.000000 55769.000000 Americas
35 Belgium Europe 11594739.000000 71158 9859.000000 17661.000000 43638.000000 61.000000 6137.000000 850.000000 1767120.000000 152407.000000 Europe
36 Kuwait Asia 4276658.000000 70045 469.000000 61610.000000 7966.000000 127.000000 16378.000000 110.000000 522200.000000 122105.000000 EasternMediterranean
37 Belarus Europe 9449001.000000 68503 580.000000 63756.000000 4167.000000 nan 7250.000000 61.000000 1344303.000000 142269.000000 Europe
38 UAE Asia 9902079.000000 61845 354.000000 55739.000000 5752.000000 nan 6246.000000 36.000000 5262658.000000 531470.000000 EasternMediterranean
39 Romania Europe 19224023.000000 57895 2566.000000 28992.000000 26337.000000 458.000000 3012.000000 133.000000 1319369.000000 68631.000000 Europe
40 Netherlands Europe 17138756.000000 56982 6153.000000 nan nan 37.000000 3325.000000 359.000000 1079860.000000 63007.000000 Europe
41 Singapore Asia 5854932.000000 54555 27.000000 48031.000000 6497.000000 nan 9318.000000 5.000000 1474372.000000 251817.000000 WesternPacific
42 Guatemala North America 17946899.000000 54339 2119.000000 42070.000000 10150.000000 5.000000 3028.000000 118.000000 172712.000000 9624.000000 Americas
43 Portugal Europe 10193593.000000 52061 1743.000000 37840.000000 12478.000000 42.000000 5107.000000 171.000000 1705474.000000 167308.000000 Europe
44 Poland Europe 37842302.000000 49515 1774.000000 35642.000000 12099.000000 72.000000 1308.000000 47.000000 2374686.000000 62752.000000 Europe
45 Nigeria Africa 206606300.000000 45244 930.000000 32430.000000 11884.000000 7.000000 219.000000 5.000000 306894.000000 1485.000000 Africa
46 Honduras North America 9919704.000000 45098 1423.000000 6116.000000 37559.000000 52.000000 4546.000000 143.000000 109292.000000 11018.000000 Americas
47 Bahrain Asia 1706669.000000 42889 156.000000 39945.000000 2788.000000 41.000000 25130.000000 91.000000 876700.000000 513691.000000 EasternMediterranean
48 Japan Asia 126435859.000000 42263 1026.000000 28877.000000 12360.000000 115.000000 334.000000 8.000000 938739.000000 7425.000000 WesternPacific
49 Armenia Asia 2963811.000000 39819 772.000000 31556.000000 7491.000000 nan 13435.000000 260.000000 171600.000000 57898.000000 Europe
50 Ghana Africa 31133483.000000 39642 199.000000 36384.000000 3059.000000 7.000000 1273.000000 6.000000 405817.000000 13035.000000 Africa
51 Kyrgyzstan Asia 6534479.000000 38659 1447.000000 30099.000000 7113.000000 24.000000 5916.000000 221.000000 267718.000000 40970.000000 Europe
52 Afghanistan Asia 39009447.000000 36896 1298.000000 25840.000000 9758.000000 31.000000 946.000000 33.000000 90396.000000 2317.000000 EasternMediterranean
53 Switzerland Europe 8660952.000000 36108 1985.000000 31600.000000 2523.000000 23.000000 4169.000000 229.000000 822764.000000 94997.000000 Europe
54 Algeria Africa 43926079.000000 33626 1273.000000 23238.000000 9115.000000 57.000000 766.000000 29.000000 nan nan Africa
55 Azerbaijan Asia 10148243.000000 33247 479.000000 29275.000000 3493.000000 66.000000 3276.000000 47.000000 766179.000000 75499.000000 Europe
56 Morocco Africa 36953359.000000 29644 449.000000 20553.000000 8642.000000 31.000000 802.000000 12.000000 1383816.000000 37448.000000 EasternMediterranean
57 Uzbekistan Asia 33516027.000000 28315 175.000000 19291.000000 8849.000000 228.000000 845.000000 5.000000 1377915.000000 41112.000000 Europe
58 Serbia Europe 8733665.000000 27332 621.000000 14047.000000 12664.000000 120.000000 3129.000000 71.000000 723137.000000 82799.000000 Europe
59 Moldova Europe 4032983.000000 26628 828.000000 18676.000000 7124.000000 362.000000 6603.000000 205.000000 128076.000000 31757.000000 Europe
60 Ireland Europe 4943200.000000 26372 1768.000000 23364.000000 1240.000000 5.000000 5335.000000 358.000000 652917.000000 132084.000000 Europe
61 Kenya Africa 53881160.000000 24411 399.000000 10444.000000 13568.000000 44.000000 453.000000 7.000000 335318.000000 6223.000000 Africa
62 Venezuela South America 28427499.000000 22299 195.000000 12146.000000 9958.000000 42.000000 784.000000 7.000000 1567431.000000 55138.000000 Americas
63 Nepal Asia 29186486.000000 21750 65.000000 15389.000000 6296.000000 nan 745.000000 2.000000 731977.000000 25079.000000 South-EastAsia
64 Austria Europe 9011577.000000 21696 719.000000 19596.000000 1381.000000 25.000000 2408.000000 80.000000 937275.000000 104008.000000 Europe
65 Costa Rica North America 5098730.000000 21070 200.000000 7038.000000 13832.000000 103.000000 4132.000000 39.000000 96110.000000 18850.000000 Americas
66 Ethiopia Africa 115223736.000000 20900 365.000000 9027.000000 11508.000000 185.000000 181.000000 3.000000 468814.000000 4069.000000 Africa
67 Australia Australia/Oceania 25528864.000000 19890 255.000000 10941.000000 8694.000000 52.000000 779.000000 10.000000 4631419.000000 181419.000000 WesternPacific
68 El Salvador North America 6489514.000000 19126 513.000000 9236.000000 9377.000000 509.000000 2947.000000 79.000000 251271.000000 38720.000000 Americas
69 Czechia Europe 10711019.000000 17731 390.000000 12320.000000 5021.000000 17.000000 1655.000000 36.000000 728670.000000 68030.000000 Europe
70 Cameroon Africa 26606188.000000 17718 391.000000 15320.000000 2007.000000 30.000000 666.000000 15.000000 149000.000000 5600.000000 Africa
71 Ivory Coast Africa 26437950.000000 16447 103.000000 12484.000000 3860.000000 nan 622.000000 4.000000 104584.000000 3956.000000 Africa
72 S. Korea Asia 51273732.000000 14519 303.000000 13543.000000 673.000000 18.000000 283.000000 6.000000 1613652.000000 31471.000000 WesternPacific
73 Denmark Europe 5794279.000000 14306 617.000000 12787.000000 902.000000 2.000000 2469.000000 106.000000 1654512.000000 285542.000000 Europe
74 Palestine Asia 5112340.000000 13398 92.000000 6907.000000 6399.000000 nan 2621.000000 18.000000 200280.000000 39176.000000 EasternMediterranean
75 Bosnia and Herzegovina Europe 3278650.000000 13396 384.000000 7042.000000 5970.000000 nan 4086.000000 117.000000 147021.000000 44842.000000 Europe
76 Bulgaria Europe 6942854.000000 13014 435.000000 7374.000000 5205.000000 47.000000 1874.000000 63.000000 294087.000000 42358.000000 Europe
77 Madagascar Africa 27755708.000000 12526 134.000000 10148.000000 2244.000000 88.000000 451.000000 5.000000 46301.000000 1668.000000 Africa
78 Sudan Africa 43943536.000000 11780 763.000000 6194.000000 4823.000000 nan 268.000000 17.000000 401.000000 9.000000 EasternMediterranean
79 North Macedonia Europe 2083365.000000 11399 517.000000 7480.000000 3402.000000 3.000000 5471.000000 248.000000 109946.000000 52773.000000 Europe
80 Senegal Africa 16783877.000000 10715 223.000000 7101.000000 3391.000000 33.000000 638.000000 13.000000 114761.000000 6838.000000 Africa
81 Norway Europe 5425471.000000 9468 256.000000 8857.000000 355.000000 3.000000 1745.000000 47.000000 472841.000000 87152.000000 Europe
82 DRC Africa 89802183.000000 9309 215.000000 8048.000000 1046.000000 nan 104.000000 2.000000 nan nan Africa
83 Malaysia Asia 32406372.000000 9038 125.000000 8713.000000 200.000000 2.000000 279.000000 4.000000 991333.000000 30591.000000 WesternPacific
84 French Guiana South America 299385.000000 8127 47.000000 7240.000000 840.000000 23.000000 27146.000000 157.000000 41412.000000 138324.000000 nan
85 Gabon Africa 2230563.000000 7787 51.000000 5609.000000 2127.000000 11.000000 3491.000000 23.000000 85369.000000 38272.000000 Africa
86 Tajikistan Asia 9557468.000000 7665 62.000000 6443.000000 1160.000000 nan 802.000000 6.000000 nan nan Europe
87 Guinea Africa 13164905.000000 7664 49.000000 6757.000000 858.000000 24.000000 582.000000 4.000000 14407.000000 1094.000000 Africa
88 Haiti North America 11416103.000000 7544 171.000000 4832.000000 2541.000000 nan 661.000000 15.000000 18443.000000 1616.000000 Americas
89 Finland Europe 5541604.000000 7532 331.000000 6980.000000 221.000000 nan 1359.000000 60.000000 389500.000000 70287.000000 Europe
90 Zambia Africa 18430129.000000 7164 199.000000 5786.000000 1179.000000 nan 389.000000 11.000000 90307.000000 4900.000000 Africa
91 Luxembourg Europe 626952.000000 7073 119.000000 5750.000000 1204.000000 9.000000 11282.000000 190.000000 623994.000000 995282.000000 Europe
92 Mauritania Africa 4660728.000000 6444 157.000000 5291.000000 996.000000 3.000000 1383.000000 34.000000 57387.000000 12313.000000 Africa
93 Paraguay South America 7141091.000000 6375 66.000000 4974.000000 1335.000000 23.000000 893.000000 9.000000 135277.000000 18943.000000 Americas
94 Albania Europe 2877470.000000 6016 188.000000 3155.000000 2673.000000 23.000000 2091.000000 65.000000 38997.000000 13553.000000 Europe
95 Lebanon Asia 6822220.000000 5672 70.000000 1974.000000 3628.000000 46.000000 831.000000 10.000000 345268.000000 50609.000000 EasternMediterranean
96 Croatia Europe 4102577.000000 5404 155.000000 4688.000000 561.000000 7.000000 1317.000000 38.000000 125317.000000 30546.000000 Europe
97 Djibouti Africa 989387.000000 5330 59.000000 5057.000000 214.000000 nan 5387.000000 60.000000 59909.000000 60552.000000 EasternMediterranean
98 Greece Europe 10417673.000000 5123 210.000000 1374.000000 3539.000000 14.000000 492.000000 20.000000 619393.000000 59456.000000 Europe
99 Libya Africa 6880353.000000 4879 107.000000 652.000000 4120.000000 nan 709.000000 16.000000 59699.000000 8677.000000 EasternMediterranean
100 Equatorial Guinea Africa 1407001.000000 4821 83.000000 2182.000000 2556.000000 nan 3426.000000 59.000000 44356.000000 31525.000000 Africa
101 Maldives Asia 541448.000000 4680 19.000000 2725.000000 1936.000000 12.000000 8643.000000 35.000000 85587.000000 158071.000000 South-EastAsia
102 CAR Africa 4837752.000000 4620 59.000000 1641.000000 2920.000000 2.000000 955.000000 12.000000 29589.000000 6116.000000 nan
103 Hungary Europe 9657785.000000 4597 600.000000 3463.000000 534.000000 8.000000 476.000000 62.000000 352546.000000 36504.000000 Europe
104 Malawi Africa 19174839.000000 4491 137.000000 2137.000000 2217.000000 4.000000 234.000000 7.000000 33466.000000 1745.000000 Africa
105 Zimbabwe Africa 14883803.000000 4339 84.000000 1264.000000 2991.000000 nan 292.000000 6.000000 140421.000000 9434.000000 Africa
106 Nicaragua North America 6632263.000000 3902 123.000000 2913.000000 866.000000 nan 588.000000 19.000000 nan nan Americas
107 Hong Kong Asia 7503041.000000 3850 46.000000 2458.000000 1346.000000 39.000000 513.000000 6.000000 692430.000000 92287.000000 WesternPacific
108 Congo Africa 5530506.000000 3546 58.000000 1589.000000 1899.000000 nan 641.000000 10.000000 nan nan Africa
109 Montenegro Europe 628074.000000 3480 60.000000 2178.000000 1242.000000 nan 5541.000000 96.000000 38427.000000 61182.000000 Europe
110 Thailand Asia 69817894.000000 3330 58.000000 3148.000000 124.000000 1.000000 48.000000 0.800000 749213.000000 10731.000000 South-EastAsia
111 Somalia Africa 15933012.000000 3227 93.000000 1728.000000 1406.000000 2.000000 203.000000 6.000000 nan nan EasternMediterranean
112 Mayotte Africa 273419.000000 3042 39.000000 2738.000000 265.000000 2.000000 11126.000000 143.000000 13000.000000 47546.000000 nan
113 Eswatini Africa 1161348.000000 2968 55.000000 1476.000000 1437.000000 5.000000 2556.000000 47.000000 20784.000000 17896.000000 Africa
114 Sri Lanka Asia 21422362.000000 2839 11.000000 2541.000000 287.000000 1.000000 133.000000 0.500000 166737.000000 7783.000000 South-EastAsia
115 Cuba North America 11325899.000000 2775 88.000000 2409.000000 278.000000 4.000000 245.000000 8.000000 285471.000000 25205.000000 Americas
116 Cabo Verde Africa 556581.000000 2734 27.000000 2010.000000 697.000000 nan 4912.000000 49.000000 61633.000000 110735.000000 Africa
117 Namibia Africa 2545264.000000 2652 15.000000 563.000000 2074.000000 24.000000 1042.000000 6.000000 29233.000000 11485.000000 Africa
118 Mali Africa 20302901.000000 2552 124.000000 1954.000000 474.000000 nan 126.000000 6.000000 25152.000000 1239.000000 Africa
119 Slovakia Europe 5459915.000000 2480 29.000000 1824.000000 627.000000 2.000000 454.000000 5.000000 272322.000000 49877.000000 Europe
120 South Sudan Africa 11206572.000000 2450 47.000000 1175.000000 1228.000000 nan 219.000000 4.000000 12044.000000 1075.000000 Africa
121 Slovenia Europe 2078968.000000 2223 125.000000 1909.000000 189.000000 2.000000 1069.000000 60.000000 135702.000000 65274.000000 Europe
122 Lithuania Europe 2718121.000000 2171 81.000000 1656.000000 434.000000 6.000000 799.000000 30.000000 540784.000000 198955.000000 Europe
123 Estonia Europe 1326627.000000 2124 63.000000 1954.000000 107.000000 nan 1601.000000 47.000000 122880.000000 92626.000000 Europe
124 Mozambique Africa 31333962.000000 2120 15.000000 795.000000 1310.000000 nan 68.000000 0.500000 65151.000000 2079.000000 Africa
125 Rwanda Africa 12981546.000000 2111 5.000000 1258.000000 848.000000 nan 163.000000 0.400000 286251.000000 22051.000000 Africa
126 Suriname South America 587154.000000 2096 29.000000 1446.000000 621.000000 9.000000 3570.000000 49.000000 2785.000000 4743.000000 Americas
127 Guinea-Bissau Africa 1972277.000000 2032 27.000000 944.000000 1061.000000 5.000000 1030.000000 14.000000 1500.000000 761.000000 Africa
128 Benin Africa 12151976.000000 1936 38.000000 1600.000000 298.000000 1.000000 159.000000 3.000000 93677.000000 7709.000000 Africa
129 Iceland Europe 341465.000000 1930 10.000000 1825.000000 95.000000 nan 5652.000000 29.000000 149693.000000 438385.000000 Europe
130 Sierra Leone Africa 7992169.000000 1877 67.000000 1427.000000 383.000000 nan 235.000000 8.000000 nan nan Africa
131 Yemen Asia 29886897.000000 1768 508.000000 898.000000 362.000000 nan 59.000000 17.000000 120.000000 4.000000 EasternMediterranean
132 Tunisia Africa 11830801.000000 1642 51.000000 1241.000000 350.000000 9.000000 139.000000 4.000000 100298.000000 8478.000000 EasternMediterranean
133 New Zealand Australia/Oceania 5002100.000000 1569 22.000000 1524.000000 23.000000 nan 314.000000 4.000000 486943.000000 97348.000000 WesternPacific
134 Angola Africa 32956300.000000 1483 64.000000 520.000000 899.000000 20.000000 45.000000 2.000000 64747.000000 1965.000000 Africa
135 Uruguay South America 3474956.000000 1318 37.000000 1079.000000 202.000000 2.000000 379.000000 11.000000 126956.000000 36535.000000 Americas
136 Latvia Europe 1883936.000000 1275 32.000000 1070.000000 173.000000 nan 677.000000 17.000000 207909.000000 110359.000000 Europe
137 Jordan Asia 10213138.000000 1232 11.000000 1171.000000 50.000000 3.000000 121.000000 1.000000 628745.000000 61562.000000 EasternMediterranean
138 Liberia Africa 5068618.000000 1224 78.000000 705.000000 441.000000 nan 241.000000 15.000000 nan nan Africa
139 Uganda Africa 45867852.000000 1223 5.000000 1102.000000 116.000000 nan 27.000000 0.100000 288367.000000 6287.000000 Africa
140 Cyprus Asia 1208238.000000 1208 19.000000 856.000000 333.000000 nan 1000.000000 16.000000 216597.000000 179267.000000 Europe
141 Georgia Asia 3988368.000000 1206 17.000000 987.000000 202.000000 nan 302.000000 4.000000 240473.000000 60294.000000 Europe
142 Burkina Faso Africa 20954852.000000 1158 54.000000 961.000000 143.000000 nan 55.000000 3.000000 nan nan Africa
143 Niger Africa 24281433.000000 1153 69.000000 1057.000000 27.000000 nan 47.000000 3.000000 9052.000000 373.000000 Africa
144 Togo Africa 8296582.000000 1012 22.000000 697.000000 293.000000 2.000000 122.000000 3.000000 45767.000000 5516.000000 Africa
145 Syria Asia 17539600.000000 999 48.000000 311.000000 640.000000 nan 57.000000 3.000000 nan nan EasternMediterranean
146 Jamaica North America 2962478.000000 958 12.000000 745.000000 201.000000 nan 323.000000 4.000000 41840.000000 14123.000000 Americas
147 Malta Europe 441663.000000 946 9.000000 670.000000 267.000000 nan 2142.000000 20.000000 136713.000000 309541.000000 Europe
148 Andorra Europe 77278.000000 944 52.000000 828.000000 64.000000 1.000000 12216.000000 673.000000 3750.000000 48526.000000 Europe
149 Chad Africa 16467965.000000 942 76.000000 838.000000 28.000000 nan 57.000000 5.000000 nan nan Africa
150 Gambia Africa 2422754.000000 935 16.000000 136.000000 783.000000 nan 386.000000 7.000000 5183.000000 2139.000000 Africa
151 Sao Tome and Principe Africa 219544.000000 878 15.000000 797.000000 66.000000 nan 3999.000000 68.000000 3079.000000 14025.000000 Africa
152 Botswana Africa 2356075.000000 804 2.000000 63.000000 739.000000 1.000000 341.000000 0.800000 68423.000000 29041.000000 Africa
153 Bahamas North America 393616.000000 761 14.000000 91.000000 656.000000 1.000000 1933.000000 36.000000 4814.000000 12230.000000 Americas
154 Vietnam Asia 97425470.000000 747 10.000000 392.000000 345.000000 nan 8.000000 0.100000 482456.000000 4952.000000 WesternPacific
155 Lesotho Africa 2143943.000000 742 23.000000 175.000000 544.000000 nan 346.000000 11.000000 8771.000000 4091.000000 Africa
156 Diamond Princess nan nan 712 13.000000 651.000000 48.000000 4.000000 nan nan nan nan nan
157 San Marino Europe 33938.000000 699 42.000000 657.000000 0.000000 nan 20596.000000 1238.000000 6068.000000 178797.000000 Europe
158 Réunion Africa 895952.000000 671 5.000000 592.000000 74.000000 3.000000 749.000000 6.000000 35419.000000 39532.000000 nan
159 Channel Islands Europe 174022.000000 597 47.000000 533.000000 17.000000 nan 3431.000000 270.000000 30721.000000 176535.000000 nan
160 Guyana South America 786936.000000 538 22.000000 189.000000 327.000000 2.000000 684.000000 28.000000 5165.000000 6563.000000 Americas
161 Tanzania Africa 59886383.000000 509 21.000000 183.000000 305.000000 7.000000 8.000000 0.400000 nan nan Africa
162 Taiwan Asia 23821199.000000 477 7.000000 443.000000 27.000000 nan 20.000000 0.300000 82737.000000 3473.000000 WesternPacific
163 Comoros Africa 871326.000000 396 7.000000 340.000000 49.000000 nan 454.000000 8.000000 nan nan Africa
164 Burundi Africa 11922216.000000 395 1.000000 304.000000 90.000000 nan 33.000000 0.080000 15614.000000 1310.000000 Africa
165 Myanmar Asia 54446389.000000 357 6.000000 308.000000 43.000000 nan 7.000000 0.100000 122290.000000 2246.000000 South-EastAsia
166 Mauritius Africa 1271985.000000 344 10.000000 334.000000 0.000000 nan 270.000000 8.000000 205285.000000 161389.000000 Africa
167 Isle of Man Europe 85078.000000 336 24.000000 312.000000 0.000000 nan 3949.000000 282.000000 8627.000000 101401.000000 nan
168 Mongolia Asia 3283344.000000 293 nan 260.000000 33.000000 1.000000 89.000000 nan 38334.000000 11675.000000 WesternPacific
169 Eritrea Africa 3551175.000000 282 nan 225.000000 57.000000 nan 79.000000 nan nan nan Africa
170 Guadeloupe North America 400131.000000 279 14.000000 179.000000 86.000000 nan 697.000000 35.000000 18476.000000 46175.000000 nan
171 Martinique North America 375235.000000 276 15.000000 98.000000 163.000000 1.000000 736.000000 40.000000 12227.000000 32585.000000 nan
172 Faeroe Islands Europe 48882.000000 266 nan 192.000000 74.000000 1.000000 5442.000000 nan 43045.000000 880590.000000 nan
173 Aruba North America 106812.000000 263 3.000000 114.000000 146.000000 nan 2462.000000 28.000000 14047.000000 131511.000000 nan
174 Cambodia Asia 16741375.000000 243 nan 210.000000 33.000000 1.000000 15.000000 nan 67807.000000 4050.000000 WesternPacific
175 Trinidad and Tobago North America 1399950.000000 210 8.000000 135.000000 67.000000 nan 150.000000 6.000000 9559.000000 6828.000000 Americas
176 Cayman Islands North America 65798.000000 203 1.000000 202.000000 0.000000 nan 3085.000000 15.000000 31108.000000 472780.000000 nan
177 Gibraltar Europe 33690.000000 190 nan 184.000000 6.000000 nan 5640.000000 nan 23063.000000 684565.000000 nan
178 Papua New Guinea Australia/Oceania 8963009.000000 163 3.000000 53.000000 107.000000 nan 18.000000 0.300000 10808.000000 1206.000000 WesternPacific
179 Sint Maarten North America 42924.000000 160 16.000000 64.000000 80.000000 3.000000 3728.000000 373.000000 1115.000000 25976.000000 nan
180 Bermuda North America 62254.000000 157 9.000000 144.000000 4.000000 nan 2522.000000 145.000000 26352.000000 423298.000000 Americas
181 Brunei Asia 437893.000000 141 3.000000 138.000000 0.000000 nan 322.000000 7.000000 41148.000000 93968.000000 nan
182 Barbados North America 287411.000000 133 7.000000 100.000000 26.000000 nan 463.000000 24.000000 12233.000000 42563.000000 Americas
183 Turks and Caicos North America 38768.000000 129 2.000000 39.000000 88.000000 3.000000 3327.000000 52.000000 1252.000000 32295.000000 nan
184 Seychelles Africa 98408.000000 126 nan 124.000000 2.000000 nan 1280.000000 nan nan nan Africa
185 Monaco Europe 39270.000000 125 4.000000 105.000000 16.000000 2.000000 3183.000000 102.000000 38209.000000 972982.000000 Europe
186 Bhutan Asia 772443.000000 105 nan 93.000000 12.000000 nan 136.000000 nan 54589.000000 70671.000000 South-EastAsia
187 Antigua and Barbuda North America 98010.000000 92 3.000000 76.000000 13.000000 1.000000 939.000000 31.000000 1500.000000 15305.000000 Americas
188 Liechtenstein Europe 38139.000000 89 1.000000 85.000000 3.000000 nan 2334.000000 26.000000 900.000000 23598.000000 Europe
189 Belize North America 398312.000000 86 2.000000 31.000000 53.000000 2.000000 216.000000 5.000000 3679.000000 9236.000000 Americas
190 French Polynesia Australia/Oceania 281072.000000 64 nan 62.000000 2.000000 nan 228.000000 nan 5849.000000 20810.000000 nan
191 St. Vincent Grenadines North America 110976.000000 56 nan 46.000000 10.000000 nan 505.000000 nan 2447.000000 22050.000000 nan
192 Saint Martin North America 38729.000000 53 3.000000 41.000000 9.000000 1.000000 1368.000000 77.000000 1183.000000 30546.000000 nan
193 Macao Asia 650193.000000 46 nan 46.000000 0.000000 nan 71.000000 nan 4071.000000 6261.000000 nan
194 Curaçao North America 164161.000000 31 1.000000 28.000000 2.000000 nan 189.000000 6.000000 1080.000000 6579.000000 nan
195 Fiji Australia/Oceania 897095.000000 27 1.000000 18.000000 8.000000 nan 30.000000 1.000000 6693.000000 7461.000000 WesternPacific
196 Saint Lucia North America 183712.000000 25 nan 24.000000 1.000000 nan 136.000000 nan 3895.000000 21202.000000 Americas
197 Timor-Leste Asia 1320812.000000 25 nan 24.000000 1.000000 nan 19.000000 nan 4238.000000 3209.000000 South-EastAsia
198 Grenada North America 112576.000000 24 nan 23.000000 1.000000 nan 213.000000 nan 6252.000000 55536.000000 Americas
199 New Caledonia Australia/Oceania 285769.000000 22 nan 22.000000 0.000000 nan 77.000000 nan 11099.000000 38839.000000 nan
200 Laos Asia 7285750.000000 20 nan 19.000000 1.000000 nan 3.000000 nan 29374.000000 4032.000000 WesternPacific
201 Dominica North America 72004.000000 18 nan 18.000000 0.000000 nan 250.000000 nan 1005.000000 13958.000000 Americas
202 Saint Kitts and Nevis North America 53237.000000 17 nan 16.000000 1.000000 nan 319.000000 nan 1146.000000 21526.000000 Americas
203 Greenland North America 56780.000000 14 nan 14.000000 0.000000 nan 247.000000 nan 5977.000000 105266.000000 Europe
204 Montserrat North America 4992.000000 13 1.000000 10.000000 2.000000 nan 2604.000000 200.000000 61.000000 12220.000000 nan
205 Caribbean Netherlands North America 26247.000000 13 nan 7.000000 6.000000 nan 495.000000 nan 424.000000 16154.000000 nan
206 Falkland Islands South America 3489.000000 13 nan 13.000000 0.000000 nan 3726.000000 nan 1816.000000 520493.000000 nan
207 Vatican City Europe 801.000000 12 nan 12.000000 0.000000 nan 14981.000000 nan nan nan Europe
208 Western Sahara Africa 598682.000000 10 1.000000 8.000000 1.000000 nan 17.000000 2.000000 nan nan Africa
In [ ]:
 

function For Comparison that will compare different stuffs

In [75]:
def plot(df,x,y,xaxis_label,yaxis_label,title):
    fig = px.bar(worldometer.head(10), y=y,x=x,color='WHO Region')
    fig.update_layout(title=title,xaxis_title=xaxis_label,yaxis_title=yaxis_label)
    fig.show()
Comparison of Deaths/Million of 10 Most Affected Countries'
In [76]:
plot(worldometer.head(10),'Country/Region','Deaths/1M pop','Country','Deaths/Million','Comparison of Deaths/Million of 10 Most Affected Countries')
Comparison of Tests/Million of 10 Most Affected Countries
In [77]:
plot(worldometer.head(10),'Country/Region','Tests/1M pop','Country','Tests/M pop','Comparison of Tests/Million of 10 Most Affected Countries')
In [78]:
'''
fig = go.Figure()
fig.add_trace(go.Bar(x=worldometer['Country/Region'].head(10), y=worldometer['TotalTests'].head(10)))
fig.update_layout(
    title="Plot Title",
    xaxis_title="X Axis Title",
    yaxis_title="X Axis Title")
fig.show()
'''
Out[78]:
'\nfig = go.Figure()\nfig.add_trace(go.Bar(x=worldometer[\'Country/Region\'].head(10), y=worldometer[\'TotalTests\'].head(10)))\nfig.update_layout(\n    title="Plot Title",\n    xaxis_title="X Axis Title",\n    yaxis_title="X Axis Title")\nfig.show()\n'
In [79]:
'''
fig = px.bar(worldometer.head(10), y='Deaths/1M pop',x='Country/Region',color='WHO Region',height=400)
fig.update_layout(title='Comparison of Deaths/Million of 10 Most Affected Countries',xaxis_title='Country',yaxis_title='Deaths/Million')
fig.show()'''
Out[79]:
"\nfig = px.bar(worldometer.head(10), y='Deaths/1M pop',x='Country/Region',color='WHO Region',height=400)\nfig.update_layout(title='Comparison of Deaths/Million of 10 Most Affected Countries',xaxis_title='Country',yaxis_title='Deaths/Million')\nfig.show()"
In [ ]:
 

extract latitudes & longtidues of locations

In [81]:
import geopy
from geopy.geocoders import Nominatim
In [83]:
geolocator=Nominatim(user_agent="app")
In [84]:
location = geolocator.geocode("USA")
print(location.latitude)
39.7837304
In [85]:
location.longitude
Out[85]:
-100.4458825
In [86]:
latest_data.head()
Out[86]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
In [87]:
df=latest_data.copy()
In [88]:
df.head()
Out[88]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
In [89]:
df.shape
Out[89]:
(47376, 5)
In [90]:
df[df['Country']=='Afghanistan']
Out[90]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
... ... ... ... ... ...
247 2020-09-25 Afghanistan 39186 32619 1451
248 2020-09-26 Afghanistan 39192 32635 1453
249 2020-09-27 Afghanistan 39227 32642 1453
250 2020-09-28 Afghanistan 39233 32642 1455
251 2020-09-29 Afghanistan 39254 32746 1458

252 rows × 5 columns

In [91]:
df2=df.groupby(['Country'])[['Confirmed','Recovered','Deaths']].max().reset_index()
In [92]:
df2.head()
Out[92]:
Country Confirmed Recovered Deaths
0 Afghanistan 39254 32746 1458
1 Albania 13518 7732 384
2 Algeria 51368 36063 1726
3 Andorra 1966 1265 53
4 Angola 4905 1833 179
In [93]:
df2[df2['Country']=='India']
Out[93]:
Country Confirmed Recovered Deaths
79 India 6145291 5101397 96318
In [94]:
lat_lon=[]
geolocator=Nominatim(user_agent="app")
for location in df2['Country']:
    location = geolocator.geocode(location)
    if location is None:
        lat_lon.append(np.nan)
    else:    
        geo=(location.latitude,location.longitude)
        lat_lon.append(geo)
In [95]:
lat_lon
Out[95]:
[(33.7680065, 66.2385139),
 (41.000028, 19.9999619),
 (28.0000272, 2.9999825),
 (42.5407167, 1.5732033),
 (-11.8775768, 17.5691241),
 (17.2234721, -61.9554608),
 (-34.9964963, -64.9672817),
 (40.7696272, 44.6736646),
 (-24.7761086, 134.755),
 (47.2000338, 13.199959),
 (40.3936294, 47.7872508),
 (24.7736546, -78.0000547),
 (26.1551249, 50.5344606),
 (24.4768783, 90.2932426),
 (13.1500331, -59.5250305),
 (53.4250605, 27.6971358),
 (50.6402809, 4.6667145),
 (16.8259793, -88.7600927),
 (9.5293472, 2.2584408),
 (27.549511, 90.5119273),
 (-17.0568696, -64.9912286),
 (44.3053476, 17.5961467),
 (-23.1681782, 24.5928742),
 (-10.3333333, -53.2),
 (4.4137155, 114.5653908),
 (42.6073975, 25.4856617),
 (12.0753083, -1.6880314),
 (17.1750495, 95.9999652),
 (-3.3634357, 29.8870575),
 (16.0000552, -24.0083947),
 (13.5066394, 104.869423),
 (4.6125522, 13.1535811),
 (61.0666922, -107.9917071),
 (7.0323598, 19.9981227),
 (15.6134137, 19.0156172),
 (-31.7613365, -71.3187697),
 (35.000074, 104.999927),
 (2.8894434, -73.783892),
 (-12.2045176, 44.2832964),
 (-0.7264327, 15.6419155),
 (-2.9814344, 23.8222636),
 (10.2735633, -84.0739102),
 (7.9897371, -5.5679458),
 (45.5643442, 17.0118954),
 (23.0131338, -80.8328748),
 (34.9823018, 33.1451285),
 (49.8167003, 15.4749544),
 (55.670249, 10.3333283),
 (53.8953584, 27.5554078),
 (11.8145966, 42.8453061),
 (19.0974031, -70.3028026),
 (19.0974031, -70.3028026),
 (-1.3397668, -79.3666965),
 (26.2540493, 29.2675469),
 (13.8000382, -88.9140683),
 (1.613172, 10.5170357),
 (15.9500319, 37.9999668),
 (58.7523778, 25.3319078),
 (-26.5624806, 31.3991317),
 (10.2116702, 38.6521203),
 (-18.1239696, 179.0122737),
 (63.2467777, 25.9209164),
 (46.603354, 1.8883335),
 (-0.8999695, 11.6899699),
 (13.470062, -15.4900464),
 (32.3293809, -83.1137366),
 (51.0834196, 10.4234469),
 (8.0300284, -1.0800271),
 (38.9953683, 21.9877132),
 (12.1360374, -61.6904045),
 (15.6356088, -89.8988087),
 (10.7226226, -10.7083587),
 (12.100035, -14.9000214),
 (4.8417097, -58.6416891),
 (19.1399952, -72.3570972),
 (38.9247244, -77.06572732690151),
 (15.2572432, -86.0755145),
 (47.1817585, 19.5060937),
 (64.9841821, -18.1059013),
 (22.3511148, 78.6677428),
 (-2.4833826, 117.8902853),
 (32.6475314, 54.5643516),
 (33.0955793, 44.1749775),
 (52.865196, -7.9794599),
 (31.5313113, 34.8667654),
 (42.6384261, 12.674297),
 (18.1152958, -77.1598454610168),
 (36.5748441, 139.2394179),
 (31.1667049, 36.941628),
 (47.2286086, 65.2093197),
 (1.4419683, 38.4313975),
 (36.638392, 127.6961188),
 (42.5869578, 20.9021231),
 (29.2733964, 47.4979476),
 (41.5089324, 74.724091),
 (20.0171109, 103.378253),
 (56.8406494, 24.7537645),
 (33.8750629, 35.843409),
 (-29.6039267, 28.3350193),
 (5.7499721, -9.3658524),
 (26.8234472, 18.1236723),
 (47.1416307, 9.5531527),
 (55.3500003, 23.7499997),
 (49.8158683, 6.1296751),
 (52.4387696, 4.8185293),
 (-18.9249604, 46.4416422),
 (-13.2687204, 33.9301963),
 (4.5693754, 102.2656823),
 (4.7064352, 73.3287853),
 (16.3700359, -2.2900239),
 (35.8885993, 14.4476911),
 (20.2540382, -9.2399263),
 (-20.2759451, 57.5703566),
 (19.4326296, -99.1331785),
 (47.2879608, 28.5670941),
 (43.7323492, 7.4276832),
 (46.8250388, 103.8499736),
 (42.9868853, 19.5180992),
 (31.1728205, -7.3362482),
 (-19.302233, 34.9144977),
 (-23.2335499, 17.3231107),
 (28.1083929, 84.0917139),
 (52.5001698, 5.7480821),
 (-41.5000831, 172.8344077),
 (12.6090157, -85.2936911),
 (17.7356214, 9.3238432),
 (9.6000359, 7.9999721),
 (41.6171214, 21.7168387),
 (64.5731537, 11.52803643954819),
 (21.0000287, 57.0036901),
 (30.3308401, 71.247499),
 (8.559559, -81.1308434),
 (-5.6816069, 144.2489081),
 (-23.3165935, -58.1693445),
 (-6.8699697, -75.0458515),
 (12.7503486, 122.7312101),
 (52.215933, 19.134422),
 (40.0332629, -7.8896263),
 (25.3336984, 51.2295295),
 (45.9852129, 24.6859225),
 (64.6863136, 97.7453061),
 (-1.9646631, 30.0644358),
 (17.250512, -62.6725973),
 (13.8250489, -60.975036),
 (12.90447, -61.2765569),
 (43.9458623, 12.458306),
 (0.8875498, 6.9648718),
 (25.6242618, 42.3528328),
 (14.4750607, -14.4529612),
 (44.024322850000004, 21.07657433209902),
 (-4.6574977, 55.4540146),
 (8.6400349, -11.8400269),
 (1.3408630000000001, 103.83039182212079),
 (48.7411522, 19.4528646),
 (45.8133113, 14.4808369),
 (8.3676771, 49.083416),
 (-28.8166236, 24.991639),
 (7.8699431, 29.6667897),
 (39.3262345, -4.8380649),
 (7.5554942, 80.7137847),
 (14.5844444, 29.4917691),
 (4.1413025, -56.0771187),
 (59.6749712, 14.5208584),
 (46.7985624, 8.2319736),
 (34.6401861, 39.0494106),
 (23.59829785, 120.83536313817521),
 (38.6281733, 70.8156541),
 (-6.5247123, 35.7878438),
 (14.8971921, 100.83273),
 (-8.5151979, 125.8375756),
 (8.7800265, 1.0199765),
 (10.8677845, -60.9821067),
 (33.8439408, 9.400138),
 (38.9597594, 34.9249653),
 (39.7837304, -100.4458825),
 (1.5333554, 32.2166578),
 (49.4871968, 31.2718321),
 (24.0002488, 53.9994829),
 (54.7023545, -3.2765753),
 (-32.8755548, -56.0201525),
 (41.32373, 63.9528098),
 (8.0018709, -66.1109318),
 (13.2904027, 108.4265113),
 (31.4331663, 34.3779285),
 (24.1797324, -13.7667848),
 (16.3471243, 47.8915271),
 (-14.5186239, 27.5599164),
 (-18.4554963, 29.7468414)]
In [96]:
df2['geo_loc']=lat_lon
In [97]:
#### unzip it
lat,lon=zip(*np.array(df2['geo_loc']))
In [98]:
df2['lat']=lat
df2['lon']=lon
In [99]:
df2.head()
Out[99]:
Country Confirmed Recovered Deaths geo_loc lat lon
0 Afghanistan 39254 32746 1458 (33.7680065, 66.2385139) 33.768006 66.238514
1 Albania 13518 7732 384 (41.000028, 19.9999619) 41.000028 19.999962
2 Algeria 51368 36063 1726 (28.0000272, 2.9999825) 28.000027 2.999983
3 Andorra 1966 1265 53 (42.5407167, 1.5732033) 42.540717 1.573203
4 Angola 4905 1833 179 (-11.8775768, 17.5691241) -11.877577 17.569124
In [100]:
df2.drop(['geo_loc'],axis=1,inplace=True)
In [101]:
df2.head()
Out[101]:
Country Confirmed Recovered Deaths lat lon
0 Afghanistan 39254 32746 1458 33.768006 66.238514
1 Albania 13518 7732 384 41.000028 19.999962
2 Algeria 51368 36063 1726 28.000027 2.999983
3 Andorra 1966 1265 53 42.540717 1.573203
4 Angola 4905 1833 179 -11.877577 17.569124
In [102]:
df2.to_csv('F:/Spatial Analysis/Spatial_data.csv')
We have found out latitude and longitude of each location listed in the dataset using geopy.
This is used to plot maps.
In [ ]:
 

places which cases are Confirmed recently through the world in the past day alone¶

Plotting Markers on the Map Folium gives a folium.Marker() class for plotting markers on a map Just pass the latitude and longitude of the location, mention the popup and tooltip and add it to the map.

Plotting markers is a two-step process.

1) you need to create a base map on which your markers will be placed
2) and then add your markers to it:
In [1]:
import folium
In [121]:
folium.Map(tiles='openstreetmap', zoom_start=2)
Out[121]:
In [104]:
# Create a map
m = folium.Map(location=[54, 15], tiles='openstreetmap', zoom_start=2)

# Add points to the map
for id,row in df2.iterrows():
    folium.Marker(location=[row['lat'],row['lon']], popup=row['Confirmed']).add_to(m)

# Display the map
m
Out[104]:
These are places which cases are Confirmed recently through the world in the past day alone
In [105]:
m = folium.Map(location=[54, 15], tiles='openstreetmap', zoom_start=2)

# Add points to the map
for idx, row in df2.iterrows():
    folium.Marker([row['lat'], row['lon']], popup=row['Recovered']).add_to(m)

# Display the map
m
Out[105]:
In [ ]:
 
In [106]:
m = folium.Map(location=[54, 15], tiles='openstreetmap', zoom_start=2)

# Add points to the map
for idx, row in df2.iterrows():
    folium.Marker([row['lat'], row['lon']], popup=row['Deaths']).add_to(m)

# Display the map
m
Out[106]:
Deaths are from these marked placesin the past day alone
In [ ]:
 
In [107]:
m = folium.Map(location=[54,15], tiles='cartodbpositron', zoom_start=2)

# Add points to the map
from folium.plugins import MarkerCluster
mc = MarkerCluster()
for idx, row in df2.iterrows():
    mc.add_child(folium.Marker([row['lat'], row['lon']],popup=row['Confirmed']))
m.add_child(mc)

# Display the map
m
Out[107]:
These are the Total number cases registered till date in respective regions through out the world
In [108]:
from folium.plugins import HeatMap
In [109]:
df2.head()
Out[109]:
Country Confirmed Recovered Deaths lat lon
0 Afghanistan 39254 32746 1458 33.768006 66.238514
1 Albania 13518 7732 384 41.000028 19.999962
2 Algeria 51368 36063 1726 28.000027 2.999983
3 Andorra 1966 1265 53 42.540717 1.573203
4 Angola 4905 1833 179 -11.877577 17.569124
In [110]:
# Create map with overall cases registered
m = folium.Map(location=[54,15], zoom_start=2)
HeatMap(data=df2[['lat', 'lon','Confirmed']], radius=15).add_to(m)

# Show the map
m
Out[110]:

In these regions the effect of corona virus is more till date. Countries like Brazil,India & US are suffering a lot.

In [ ]:
 
In [ ]:
 
In [ ]: